import React, { Component, lazy, Suspense } from 'react'
import { HashRouter as Router, Route, Switch } from "react-router-dom"
import store from "../store"
const Home = lazy(() => import("../view/list"))
const Parseresult1 = lazy(() => import("../view/parseresult"))
const Reportparseresult = lazy(() => import("../view/ReportParse"))
const Login = lazy(() => import("../Login/login"))
const RouteWithSubRoutes = (route: any) => {
    return (
        <Route
            exact={route.exact}
            path={route.path}
            render={props => {
                document.title = route.title || "智能撰写材料结构化系统";
                return <route.component {...props} routes={route.routes}></route.component>
            }}
        />
    );
};
export default class index extends Component<any, any> {

    constructor(props: any) {
        super(props);
        this.state = {
            pathlist: [
                { component: Login, path: "/", exact: true },
                { component: Home, path: "/parseList", exact: true },
                { component: Parseresult1, path: "/parseresult/:id", },
                { component: Reportparseresult, path: "/reportparseresult/:id" }
            ]
        }
    }

    render() {
        return (
            <div>
                <Router>
                    <Suspense fallback={<div>加载中</div>}>
                        <Switch>
                            {this.state.pathlist.map((item: any, index: number) => {
                                return <RouteWithSubRoutes key={index} {...item} />
                            }
                            )}
                        </Switch>
                    </Suspense>
                </Router>
            </div>
        )
    }
}
// export default () => {
//     return allRouters.map((route, i) => {
//         return <RouteWithSubRoutes key={i} {...route} />
//     })
// };